package com.example.controller;
import com.example.exception.CustomException;
import com.example.common.Result;
import com.example.common.ResultCode;
import com.example.entity.*;
import com.example.service.*;
import com.example.service.impl.CollectServiceImpl;
import com.example.vo.XuekejingsaiVo;import com.example.vo.YuanxiVo;import com.example.vo.BanjiVo;import com.example.vo.XueshengVo;import com.example.vo.BaomingVo;import com.example.vo.JidiVo;import com.example.vo.XiangmuleibieVo;import com.example.vo.HuodongleibieVo;import com.example.vo.ZhuanyeVo;import com.example.vo.ChuangxinhuodongVo;import com.example.vo.JibieVo;import com.example.vo.SuanfaleibieVo;import com.example.vo.ZuopinleibieVo;import com.example.vo.ChengjiVo;
import com.example.vo.PinglunVo;
import com.example.vo.BianhuantuVo;
import com.example.vo.XinwentongzhiVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping(value = "/front")
public class FrontController {
    @Autowiredprivate XuekejingsaiService  xuekejingsaiService;@Autowiredprivate YuanxiService  yuanxiService;@Autowiredprivate BanjiService  banjiService;@Autowiredprivate XueshengService  xueshengService;@Autowiredprivate BaomingService  baomingService;@Autowiredprivate JidiService  jidiService;@Autowiredprivate XiangmuleibieService  xiangmuleibieService;@Autowiredprivate HuodongleibieService  huodongleibieService;@Autowiredprivate ZhuanyeService  zhuanyeService;@Autowiredprivate ChuangxinhuodongService  chuangxinhuodongService;@Autowiredprivate JibieService  jibieService;@Autowiredprivate SuanfaleibieService  suanfaleibieService;@Autowiredprivate ZuopinleibieService  zuopinleibieService;@Autowiredprivate ChengjiService  chengjiService;
    @Autowired
    private PinglunService pinglunService;
	@Autowired
    private BianhuantuService  bianhuantuService;
    @Autowired
    private XinwentongzhiService  xinwentongzhiService;
    @Autowired
    private LiuyanbanService liuyanbanService;
    @Resource
    private CollectServiceImpl collectService;

	@GetMapping("/getxuekejingsaidetail/{id}")public Result getxuekejingsaidetail(@PathVariable Integer id) {	return Result.success(xuekejingsaiService.findById(id));}@PostMapping("/xuekejingsai")public Result<XuekejingsaiVo> xuekejingsai(@RequestBody XuekejingsaiVo xuekejingsaiVo) {return Result.success(xuekejingsaiService.findPage(xuekejingsaiVo));}@GetMapping("/getxueshengdetail/{id}")public Result getxueshengdetail(@PathVariable Integer id) {	return Result.success(xueshengService.findById(id));}@PostMapping("/xuesheng")public Result<XueshengVo> xuesheng(@RequestBody XueshengVo xueshengVo) {return Result.success(xueshengService.findPage(xueshengVo));}@PostMapping("/zhucexuesheng")public Result zhucexuesheng(@RequestBody Xuesheng xuesheng) {xueshengService.add(xuesheng);return Result.success();}@PostMapping("/findxueshengxuehao")public Result findxueshengxuehao(@RequestBody Xuesheng xuesheng) {xueshengService.findxueshengxuehao(xuesheng);return Result.success();}@PostMapping("/loginxuesheng")public Result loginxuesheng(@RequestBody Xuesheng xuesheng) {return Result.success(xueshengService.login(xuesheng));}@GetMapping("/getbaomingdetail/{id}")public Result getbaomingdetail(@PathVariable Integer id) {	return Result.success(baomingService.findById(id));}@PostMapping("/postbaoming")public Result<Baoming> postbaoming(@RequestBody Baoming baoming) {return Result.success(baomingService.add(baoming));}@GetMapping("/getjididetail/{id}")public Result getjididetail(@PathVariable Integer id) {	return Result.success(jidiService.findById(id));}@PostMapping("/jidi")public Result<JidiVo> jidi(@RequestBody JidiVo jidiVo) {return Result.success(jidiService.findPage(jidiVo));}@GetMapping("/getchuangxinhuodongdetail/{id}")public Result getchuangxinhuodongdetail(@PathVariable Integer id) {	return Result.success(chuangxinhuodongService.findById(id));}@PostMapping("/chuangxinhuodong")public Result<ChuangxinhuodongVo> chuangxinhuodong(@RequestBody ChuangxinhuodongVo chuangxinhuodongVo) {return Result.success(chuangxinhuodongService.findPage(chuangxinhuodongVo));}@GetMapping("/getchengjidetail/{id}")public Result getchengjidetail(@PathVariable Integer id) {	return Result.success(chengjiService.findById(id));}@PostMapping("/chengji")public Result<ChengjiVo> chengji(@RequestBody ChengjiVo chengjiVo) {return Result.success(chengjiService.findPage(chengjiVo));}
	
	@PostMapping("/postpinglun")
    public Result<Pinglun> postpinglun(@RequestBody Pinglun pinglun) {
        return Result.success(pinglunService.add(pinglun));
    }
    @PostMapping("/pinglun")
    public Result<PinglunVo> pinglun(@RequestBody PinglunVo pinglunVo) {
        return Result.success(pinglunService.findPage(pinglunVo));
    }
	
	@GetMapping("/bianhuantu")
    public Result bianhuantu() {
        return Result.success(bianhuantuService.list());
    }
   
    @GetMapping("/xinwentongzhi")
    public Result xinwentongzhi() {
        return Result.success(xinwentongzhiService.list());
    }
    @GetMapping("/getxinwentongzhi/{id}")
    public Result getxinwentongzhi(@PathVariable Integer id) {
        return Result.success(xinwentongzhiService.findById(id));
    }
    @PostMapping("/addLiuyan")
    public Result addComment(@RequestBody Liuyanban liuyanban) {
        liuyanbanService.add(liuyanban);
        return Result.success();
    }
    @GetMapping("/getLiuyan")
    public Result<List<Liuyanban>> getCommentTiezi() {
        return Result.success(liuyanbanService.getLiuyan());
    }
    @PostMapping("/addCollect")
    public Result addCollect(@RequestBody Collect collect) {
        Collect collect1 = collectService.add(collect);
        if(collect1  == null){
            return Result.success("请勿重复收藏");
        }
        return Result.success();
    }
    @DeleteMapping("/deleteCollect/{id}")
    public Result deleteCollect(@PathVariable Integer id) {
        collectService.delete(id);
        return Result.success();
    }
	@PostMapping("/getUserCollect")
    public Result getUserCollect(@RequestBody Collect collect) {
        return Result.success(collectService.findFrontPages(collect.getUserId()));
    }
    @DeleteMapping("/deleteCollect/{id}/{userId}")
    public Result deleteCollect(@PathVariable Integer id,@PathVariable Integer userId) {
        collectService.deleteByUserId(id,userId);
        return Result.success();
    }
	
	@PutMapping("/xuekejingsai")public Result updateXuekejingsai(@RequestBody XuekejingsaiVo xuekejingsai) {xuekejingsaiService.update(xuekejingsai);return Result.success();}@PutMapping("/yuanxi")public Result updateYuanxi(@RequestBody YuanxiVo yuanxi) {yuanxiService.update(yuanxi);return Result.success();}@PutMapping("/banji")public Result updateBanji(@RequestBody BanjiVo banji) {banjiService.update(banji);return Result.success();}@PutMapping("/xuesheng")public Result updateXuesheng(@RequestBody XueshengVo xuesheng) {xueshengService.update(xuesheng);return Result.success();}@PutMapping("/baoming")public Result updateBaoming(@RequestBody BaomingVo baoming) {baomingService.update(baoming);return Result.success();}@PutMapping("/jidi")public Result updateJidi(@RequestBody JidiVo jidi) {jidiService.update(jidi);return Result.success();}@PutMapping("/xiangmuleibie")public Result updateXiangmuleibie(@RequestBody XiangmuleibieVo xiangmuleibie) {xiangmuleibieService.update(xiangmuleibie);return Result.success();}@PutMapping("/huodongleibie")public Result updateHuodongleibie(@RequestBody HuodongleibieVo huodongleibie) {huodongleibieService.update(huodongleibie);return Result.success();}@PutMapping("/zhuanye")public Result updateZhuanye(@RequestBody ZhuanyeVo zhuanye) {zhuanyeService.update(zhuanye);return Result.success();}@PutMapping("/chuangxinhuodong")public Result updateChuangxinhuodong(@RequestBody ChuangxinhuodongVo chuangxinhuodong) {chuangxinhuodongService.update(chuangxinhuodong);return Result.success();}@PutMapping("/jibie")public Result updateJibie(@RequestBody JibieVo jibie) {jibieService.update(jibie);return Result.success();}@PutMapping("/suanfaleibie")public Result updateSuanfaleibie(@RequestBody SuanfaleibieVo suanfaleibie) {suanfaleibieService.update(suanfaleibie);return Result.success();}@PutMapping("/zuopinleibie")public Result updateZuopinleibie(@RequestBody ZuopinleibieVo zuopinleibie) {zuopinleibieService.update(zuopinleibie);return Result.success();}@PutMapping("/chengji")public Result updateChengji(@RequestBody ChengjiVo chengji) {chengjiService.update(chengji);return Result.success();}

}
